package com.jajahome.feature.user.fragment;

import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.jajahome.R;
import com.jajahome.feature.user.activity.ChipsAct;
import com.jajahome.feature.user.activity.CrowDetailAct;
import com.jajahome.model.CrowModel;
import com.jajahome.util.StringUtil;
import com.squareup.picasso.Picasso;

/**
 * Created by tuxuesong on 2018/6/5.
 */

public class CrowPageFragment extends Fragment {

    /**
     * 向轮播图Fragment传数据
     */
    public static final String BEAN = "BEAN";

    /**
     * 轮播图数据
     */
    public static CrowPageFragment newInstance(CrowModel.DataEntity.CrowdListEntity bannerBean) {
        Bundle bundle = new Bundle();
        bundle.putSerializable(BEAN, bannerBean);
        CrowPageFragment imagePageFragment = new CrowPageFragment();
        imagePageFragment.setArguments(bundle);
        return imagePageFragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //拿到数据
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        Bundle bundle = getArguments();
        final CrowModel.DataEntity.CrowdListEntity bannerBean = (CrowModel.DataEntity.CrowdListEntity) bundle.getSerializable(BEAN);
        View view = inflater.inflate(R.layout.item_banner, container, false);
        ImageView imgBanner = (ImageView) view.findViewById(R.id.item_banner_img);
        String smallUri = bannerBean.getImage().getSmall();
        if (!StringUtil.isEmpty(smallUri)) {
            Picasso.with(getContext())
                    .load(smallUri)
                    .placeholder(R.mipmap.ic_bottom_background)
                    .into(imgBanner);
        }

        imgBanner.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getContext(), CrowDetailAct.class);
                intent.putExtra(CrowDetailAct.CROW_ID, bannerBean.getId());
                intent.putExtra(CrowDetailAct.AMRAISED, bannerBean.getAmRaised());
                intent.putExtra(CrowDetailAct.TARAMOUNT, bannerBean.getTarAmount());
                intent.putExtra(CrowDetailAct.MEMO, bannerBean.getMemo());
                intent.putExtra(CrowDetailAct.TYPE, bannerBean.getState());
                intent.putExtra(ChipsAct.POSTAGE, bannerBean.getPostage());
                intent.putExtra(ChipsAct.BUYCOUNT,bannerBean.getBuy_count());
                getContext().startActivity(intent);
            }
        });
        return view;
    }


}
